#!/bin/bash

# xfio-agent 安装脚本

set -e

echo "Installing xfio-agent..."

# 检查Go是否安装
if ! command -v go &> /dev/null; then
    echo "Error: Go is not installed. Please install Go first."
    exit 1
fi

# 检查fio是否安装
if ! command -v fio &> /dev/null; then
    echo "Warning: fio is not installed. Installing fio..."
    if command -v apt-get &> /dev/null; then
        sudo apt-get update
        sudo apt-get install -y fio
    elif command -v yum &> /dev/null; then
        sudo yum install -y fio
    elif command -v dnf &> /dev/null; then
        sudo dnf install -y fio
    else
        echo "Error: Could not install fio. Please install fio manually."
        exit 1
    fi
fi

# 构建xfio-agent
echo "Building xfio-agent..."
cd "$(dirname "$0")"
go build -o xfio-agent .

echo "xfio-agent installed successfully!"
echo ""
echo "To run xfio-agent:"
echo "  ./xfio-agent -master=http://MASTER_IP:8000 -token=YOUR_TOKEN"
echo ""
echo "For more options:"
echo "  ./xfio-agent -h"